using System;
using System.Collections.Generic;
using UnityEngine;

public class ParallaxBackground : MonoBehaviour
{
   [SerializeField] private List<ParallaxLayer> materials;
   [SerializeField] private GameObject target;
   private PlayerController controller;
   private void Awake()
   {
       controller = target.GetComponent<PlayerController>();
    
   }

   private void Update()
   {
       foreach (var item in materials)
       {
           // 假设 "_Offset" 是一个 Vector2 类型的属性
           Vector2 offset = new Vector2();
           offset.x = -controller._currentSpeed*item.speed; // 将 x 值设置为 rb.velocity.x
           item.material.SetVector("_Offset", offset);
       }
   }
}
[Serializable]
public class ParallaxLayer
{
    public Material material;
    public float speed;
}